home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / lk_df.zip / CEH.ASM next >
Assembly Source File  |  1993-02-16  |  3KB  |  110 lines

  1. ; ------------- ceh.asm --------------------------------------------------
  2. ;       setCEH()        Install replacement Critical Error Handler to cause
  3. ;                       automatic "Fail" on drive-not-ready when testing
  4. ;                       empty floppy drives.  All other conditions are passed
  5. ;                       to the original handler
  6. ;
  7. ;       unsetCEH()      Use to deinstall our replacement CEH
  8. ;
  9. ;       use:    tasm /mx ceh.asm
  10. ;
  11. ;       written by Jesse Chisholm, 91.12.31
  12. ;       released to the Public Domain: 91.12.31
  13. ;       modified to use from C code by Jon Freivald, 92.01.12
  14.  
  15. ;_STACK segment para stack 'STACK'
  16. ;       dw      100h dup (0)
  17. ;_STACK ends
  18.  
  19. _TEXT   segment word public 'CODE'
  20.  
  21.         assume  cs:_TEXT
  22.  
  23.         PUBLIC _setCEH, _unsetCEH
  24.  
  25. Oldint24        dd      0               ; store the original address
  26.  
  27. Newint24        dd      int24           ; address of new CEH
  28.  
  29. ;
  30. ; This code is executed during program's initialization
  31. ; to install the new critical error handler.
  32. ;
  33.  
  34. _setCEH         proc    near
  35.  
  36.                 push    bx              ; save some registers
  37.                 push    dx
  38.                 push    ds
  39.                 push    es
  40.  
  41.                 mov     ax,3524h        ; get the original vector
  42.                 int     21h
  43.                 mov     word ptr Oldint24,bx
  44.                 mov     bx,es
  45.                 mov     word ptr Oldint24+2, bx
  46.  
  47.                 lds     dx,Newint24     ; DS:DX == handler address
  48.                 mov     ax,2524h        ; set new vector
  49.                 int     21h             ; transfer to MS-DOS
  50.  
  51.                 pop     es              ; restore registers
  52.                 pop     ds
  53.                 pop     dx
  54.                 pop     bx
  55.  
  56.                 ret
  57. _setCEH         endp
  58.  
  59. ;
  60. ; This code is executed in the program's termination and cleanup code
  61. ;
  62. _unsetCEH       proc    near
  63.  
  64.                 push    dx                      ; save some registers
  65.                 push    ds
  66.  
  67.                 mov     dx,word ptr Oldint24    ; check if vector ever set
  68.                 or      dx,word ptr Oldint24+2
  69.                 cmp     dx,0
  70.                 je      unsetCEHx               ; no, don't reset
  71.  
  72.                 mov     ax,2524h                ; restore old address
  73.                 lds     dx,Oldint24
  74.                 int     21h
  75.  
  76.                 xor     dx,dx                   ; zap address for next time
  77.                 mov     word ptr Oldint24,dx
  78.                 mov     word ptr Oldint24+2,dx
  79.  
  80. unsetCEHx:      pop     ds                      ; restore registers
  81.                 pop     dx
  82.  
  83.                 ret
  84. _unsetCEH       endp
  85.  
  86. ;
  87. ; This is the replacement critical error handler.
  88. ; If the drive was not ready, it causes the MS-DOS function
  89. ; to "FAIL".  All other conditions are passed to the original
  90. ; int 24 handler.
  91. ;
  92.  
  93. int24           proc    far
  94.  
  95.                 mov     ax,di           ; get error code
  96.                 cmp     al,02h          ; 02 == DRIVE NOT READY
  97.                  je     FloppyNotReady
  98.                 jmp     far ptr [Oldint24]      ; go to original handler
  99.  
  100. FloppyNotReady:
  101.                 mov     al,03h          ; 03 == Fail function call in progress
  102.  
  103.                 iret                            ; exit critical error handler
  104. int24           endp
  105.  
  106. _TEXT   ends
  107.  
  108.         end
  109.  
  110.